<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\Luodianwei;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use App\Models\Dept;

class LuodianweiController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Luodianwei(), function (Grid $grid) {
            // $grid->column('id')->sortable();
            $grid->quickSearch('mokuaidizhi', 'leixing')->placeholder('输入地址或类型等搜索...');
            // 禁用过滤器按钮
            // $grid->disableFilterButton();
            // 禁用刷新按钮
            $grid->disableRefreshButton();

            // $grid->model()->orderBy('mokuaidizhi');

            $grid->model()->orderBy('zhuji')->orderBy('huilu');

            $grid->model()->with(['dept']);

            $grid->export();

            $grid->column('mokuaidizhi')->sortable();
            $grid->column('leixing');
            $grid->column('louhao')->editable();
            $grid->column('louceng')->editable();
            $grid->column('dept.deptname', '部门名称');
            $grid->column('weizhi')->editable();
            // $grid->column('beizhu')->editable();

            $grid->column('dianweipics');
            // $grid->column('created_at');
            // $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('louhao');
                $filter->equal('louceng');
                $filter->equal('zhuji');
                $filter->equal('huilu');
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Luodianwei(), function (Show $show) {
            $show->field('id');
            $show->field('mokuaidizhi');
            $show->field('leixing');
            $show->field('louhao');
            $show->field('louceng');
            $show->field('weizhi');
            $show->field('beizhu');
            $show->field('dept_id');
            $show->field('dianweipics');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Luodianwei(), function (Form $form) {
            $form->display('id');
            $form->text('mokuaidizhi');
            $form->text('leixing');
            $form->text('louhao');
            $form->text('louceng');
            $form->text('weizhi');
            $form->text('beizhu');
            $form->text('dept_id');
            $form->text('dianweipics');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
